import "./index.scss";
import { Button, Form, Input, message } from "antd";
import { useNavigate } from "react-router-dom";
import http from "../../utils/http"

const Login = () => {
  // 定义跳转
  const navigate = useNavigate();

  // 登录成功
  const onFinish = (values: any) => {
    console.log("Success:", values);
    http({
        url:'/login',
        method:'post',
        data:values
    }).then((res:{[propName:string]:any})=>{
        console.log('666',res.data.identity);
        if(res.data.identity=='教育局'){
            message.success('登录成功')
            navigate('/home');
        }else if(res.data.identity=='中心校'){
          message.success('登录成功')
            navigate('/zhome');
        }else {
          message.error("登录失败");
        }
    })
  };

  const onFinishFailed = (errorInfo: any) => {
    console.log("Failed:", errorInfo);
  };

  return (
    <div className="login">
      <div className="box">
        <img
          src="https://img.axureshop.com/07/b8/9b/07b89b58b7ef43ddb3340e5ed6e394be/images/%E7%99%BB%E5%BD%95/u2.png"
          className="img"
        />

        <div className="title">辅导培训机构监管系统</div>

        <Form
          name="basic"
          className="form"
          initialValues={{ remember: true }}
          onFinish={onFinish}
          onFinishFailed={onFinishFailed}
          autoComplete="off"
        >
          <Form.Item
            name="username"
            rules={[{ required: true, message: "请输入账号!" }]}
          >
            <Input placeholder="账号" />
          </Form.Item>

          <Form.Item
            name="password"
            rules={[{ required: true, message: "请输入密码!" }]}
          >
            <Input.Password placeholder="密码" />
          </Form.Item>

          <Form.Item>
            <Button type="primary" htmlType="submit" className="btn">
              登录
            </Button>
          </Form.Item>
        </Form>
      </div>
    </div>
  );
};
export default Login;
